local hx__tuwei = fk.CreateSkill {
  name = "hx__tuwei",
}

hx__tuwei:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and
      data.card.trueName == "slash" and
      player:hasSkill(hx__tuwei.name) and data:isOnlyTarget(data.tos[1]) and
      player:usedSkillTimes(hx__tuwei.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {"tuwei_damage", "tuwei_extra", "beishui"}
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = hx__tuwei.name,
      prompt = "#hx__tuwei-choose",
    })
    if choice == "tuwei_extra" or choice == "beishui" then
      local extratargets = data:getExtraTargets()
      if #extratargets > 0 then 
        local tos = room:askToChoosePlayers(player, {
          targets = extratargets,
          min_num = 1,
          max_num = 1,
          prompt = "#hx__tuwei-extra-target:::" .. data.card:toLogString(),
          skill_name = hx__tuwei.name,
          cancelable = true
        })
        if #tos > 0 then
          for _, p in ipairs(tos) do
            data:addTarget(p)
          end
        end
      end
    end
    if choice == "tuwei_damage" or choice == "beishui" then
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
    if choice == "beishui" then
      room:loseHp(player, 1, hx__tuwei.name)
    end
  end,
})

return hx__tuwei